package com.boot.mall.product.service.impl;

import com.boot.mall.product.entity.BrandEntity;
import com.boot.mall.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.Query;

import com.boot.mall.product.dao.CategoryBrandRelationDao;
import com.boot.mall.product.entity.CategoryBrandRelationEntity;
import com.boot.mall.product.service.CategoryBrandRelationService;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;
    @Autowired
    private BrandService brandService;

    // 查询与分类绑定的品牌信息
    @Override
    public List<BrandEntity> getBrandsByCatId(String catId) {
        QueryWrapper<CategoryBrandRelationEntity> queryWrapper = new QueryWrapper<>();
        List<BrandEntity> brands = new ArrayList<>();
        // 根据分类id从分类品牌联系表中查询与分类绑定的品牌信息
        queryWrapper.eq("catelog_id",catId);
        // 与绑定品牌的信息
        List<CategoryBrandRelationEntity> relations = categoryBrandRelationService.list(queryWrapper);
        // 遍历联系的id值，查询品牌信息
        for (CategoryBrandRelationEntity relation : relations) {
            // 品牌信息
            BrandEntity brand = brandService.getById(relation.getBrandId());
            brands.add(brand);
        }
        return brands;
    }
}